<template>
  <div class="my_box">
    <div class="top">
      <div class="top_title">我的</div>
      <div class="top_information">
        <img :src="img" alt="加载失败" />
        <div class="xinxi">
          <p>昵称:{{ nickName }}</p>
          <p>{{ tel | teljiami }}</p>
        </div>
        <button @click="look">查看资料</button>
      </div>
    </div>
    <div class="center">
      <div class="center_top">
        <p>账户余额￥:{{ balance }}</p>
        <p>保证金待交￥:{{ deposit }}</p>
        <button @click="recharge">充值</button>
      </div>
      <div class="center_bottom">
        <div
          class="center_list"
          v-for="(item, index) in titlelist"
          :key="index"
        >
          <img :src="item.img" :alt="alt" />
          <span>{{ item.title }}</span>
          <img class="img_zz" :src="titimg" alt="" />
        </div>
      </div>
    </div>
    <van-popup
      closeable
      v-model="isshow"
      position="bottom"
      :style="{ height: '8rem' }"
    >
      <div>
        <span class="span1">代扣</span><span class="span2">费率0.05%</span>
      </div>
      <div>
        <span class="span1" @click="zhanshi">充值</span
        ><span class="span2">费率0</span>
      </div>
      <p @click="quxiao" class="p1">取消</p></van-popup
    >
    <div class="close" v-if="isclose">
      <button @click="btnclose">退出登录</button>
    </div>
    <div class="recharge">
      <van-popup
        v-model="iszhanshi"
        style="
          width: 16.5867rem;
          height: 13.92rem;
          background: #ffffff;
          opacity: 1;
          border-radius: 1rem;
        "
        ><p class="p2">提示</p>
        <p class="pb">请自行从银行卡</p>
        <div>
          <span class="spanp">{{ mybank }}</span
          ><span class="pa" @click="copyones" :data-clipboard-text="111111"
            >复制</span
          >
        </div>
        <p class="pb">
          充值<span style="color: red; fontsize: 1.1rem">{{
            '￥' + money
          }}</span
          >到电子账户
        </p>
        <div>
          <span class="spanp">{{ gsbank }}</span
          ><span class="pa">复制</span>
        </div>
        <button class="zsbtn" @click="zsbtn">确认</button>
      </van-popup>
    </div>
    <!-- <van-cell is-link>展示弹出层</van-cell> -->
    <van-popup v-model="isshowPopup" class="wzimg">
      <!-- <img class="wzimgs" src="@/assets//img/我的_slices//我的信息/王者.jpg" alt=""> -->
      还没准备好
    </van-popup>
  </div>
</template>

<script>
import { mymoto } from '@/api/login'
import { Dialog, Toast } from 'vant'
import { mapState } from 'vuex'
import router from '@/router'
import Clipboard from 'clipboard'

// import { copyone } from '@/utils/copy.js'
export default {
  mounted() {
    mymoto().then(() => {})
  },
  data() {
    return {
      isshowPopup: false,
      //我的银行卡
      mybank: 123445678912345678911,
      gsbank: 123445678912345678911,
      //需充值银行卡
      //充值金额
      money: 3000,
      //展示内容
      iszhanshi: false,
      //余额
      balance: '0.00',
      //保证金代交
      deposit: '0.00',
      //弹出框
      isshow: false,
      //昵称
      nickName: '奥特曼',
      //手机号
      tel: localStorage.tel,
      //头像
      img: require('@/assets/img/我的_slices/OIP-C.jpg'),
      //箭头图片
      titimg: require('@/assets/img/首页_slices/arrow-right(1).png'),
      //alt
      alt: '加载失败',
      titlelist: [
        {
          img: require('@/assets/img/我的_slices/组 73(1).png'),
          title: '办卡进度'
        },
        {
          img: require('@/assets/img/我的_slices/组 73(2).png'),
          title: '我的账户'
        },
        {
          img: require('@/assets/img/我的_slices/组 73(1).png'),
          title: '账单查询'
        },
        {
          img: require('@/assets/img/我的_slices/组 73(3).png'),
          title: '我的合同'
        },
        {
          img: require('@/assets/img/我的_slices/组 73(4).png'),
          title: '余额明细'
        }
      ]
    }
  },
  computed: {
    //显隐退出登录
    isclose() {
      if (localStorage.token) {
        return true
      } else {
        return false
      }
    },
    ...mapState(['telnumber'])
  },
  filters: {
    teljiami(val) {
      if (val) {
        return val.substring(3, 0) + '****' + val.substring(7)
      }
    }
  },
  methods: {
    look() {
      const [tel, token] = [localStorage.tel, localStorage.token]
      if (!tel && !token) {
        Toast.fail({ message: '先登录,在查看', closeOnClick: true })
        return false
      }
      this.isshowPopup = true
    },
    copyones() {
      console.log(this.mybank.toString().length)
      let clipboard = new Clipboard('.code')
      clipboard.on('success', (e) => {
        console.log('复制成功', e)
        Toast({
          message: '复制成功'
        })
        // 释放内存
        clipboard.destroy()
      })
      clipboard.on('error', (e) => {
        // 不支持复制
        Toast({
          message: '手机权限不支持复制功能',
          e
        })
        console.log('该浏览器不支持自动复制')
        // 释放内存
        clipboard.destroy()
      })
    },
    zhanshi() {
      this.isshow = false
      this.iszhanshi = true
    },
    btnclose() {
      Dialog.confirm({
        title: '提示',
        message: '是否确认退出'
      })
        .then(() => {
          localStorage.clear()
          ;(localStorage.token = ''), router.replace('/login')
        })
        .catch(() => {
          // on cancel
        })
    },
    recharge() {
      const [tel, token] = [localStorage.tel, localStorage.token]
      if (!tel && !token) {
        Toast.fail({ message: '先登录', closeOnClick: true })
        return false
      }
      this.isshow = true
    },
    quxiao() {
      this.isshow = false
    },
    zsbtn() {
      this.iszhanshi = false
    }
  }
}
</script>

<style lang="less" scoped>
.wzimg {
  width: 95%;
  height: 400px;
  max-width: 750px;
  border-radius: 20px;
  .wzimgs {
    width: 100%;
    height: 100%;
  }
}
.my_box {
  position: absolute !important;
  width: 100%;
  height: 100%;
  background: #f7f8fa;
  opacity: 1;
  .top {
    height: 8.88rem;
    background: url('@/assets/img/我的_slices/路径 20.png') no-repeat;
    background-size: 100% 100%;
    background-color: #fff;
    .top_title {
      text-align: center;
      font-size: 0.96rem;
      color: #fff;
      height: 2.3467rem;
      line-height: 2.3467rem;
    }
    .top_information {
      height: 5.6533rem;
      width: 18.2933rem;
      background-color: #fff;
      border-radius: 10px 10px 0px 0px;
      margin: 0.5333rem 0.8533rem 0.3733rem 0.8533rem;
      display: flex;
      flex-direction: row;
      img {
        margin: 1.3333rem 0 1.44rem 0.8rem;
        height: 2.88rem;
        width: 2.88rem;
        border-radius: 50%;
      }
      .xinxi {
        width: 5.0133rem;
        height: 2.6667rem;
        margin: 1.44rem 0 1.44rem 0.5333rem;
        p:nth-child(1) {
          font-size: 0.9067rem;
          height: 1.28rem;
          font-weight: bold;
          color: #333333;
        }
        p:nth-child(2) {
          font-size: 0.8rem;
          color: #666666;
          height: 1.12rem;
          line-height: 1.12rem;
        }
      }
      button {
        width: 3.84rem;
        height: 1.28rem;
        background: #ffecec;
        opacity: 1;
        border-radius: 24px;
        font-size: 0.64rem;
        font-family: PingFang SC;
        font-weight: 400;
        line-height: 1.28rem;
        color: #f23d3d;
        margin: 1.44rem 0.8rem 0px 4.4267rem;
      }
    }
  }
  position: relative;
  .center {
    width: 100%;
    height: 16.3467rem;
    // background-color: aqua;
    display: flex;
    flex-direction: column;
    align-items: center;
    .center_top {
      width: 18.2933rem;
      height: 2.56rem;
      background: #fbeedd;
      opacity: 1;
      border-radius: 0px 0px 0.2667rem 0.2667rem;
      color: #c6821b;
      font-size: 0.6933rem;
      margin: -0.3467rem 0 0 0;
      p {
        margin: 0.2667rem 0 0.2667rem 0.8rem;
      }
      button {
        width: 2.7733rem;
        height: 1.28rem;
        line-height: 1.28rem;
        background: #f5c079;
        opacity: 1;
        border-radius: 0.64rem;
        color: #000;
        position: relative;
        top: -2rem;
        left: 14.72rem;
      }
    }
    .center_bottom {
      height: 2.6667rem;
      width: 18.2933rem;
      margin-top: 30px;
      .center_list {
        border-radius: 15px;
        background-color: #fff;
        border-bottom: 1px solid #e7e6e6;
        display: flex;
        align-items: center;
        height: 2.6667rem;
        width: 18.2933rem;
        // background-color: #c6821b;
        img:nth-child(1) {
          width: 0.9067rem;
          height: 0.9067rem;
          margin: 34px 0 34px 20px;
        }
        .img_zz {
          background-color: transparent;
          margin-left: 460px;
        }
        span {
          width: 120px;
          color: #333;
          font-size: 30px;
          height: 42px;
          line-height: 42px;
          font-weight: 400;
          margin-left: 20px;
        }
      }
    }
  }
  .close {
    width: 686px;
    height: 88px;
    opacity: 1;
    margin: 90px 32px 0 32px;
    button {
      width: 100%;
      height: 100%;
      border-radius: 44px;
      font-size: 32px;
      color: #666;
    }
  }
  .van-popup {
    background-color: #fff;
    display: flex;
    align-items: center;
    flex-direction: column;
    div {
      height: 2.6667rem;
      line-height: 2.6667rem;
      .span1 {
        display: inline-block;
        width: 2.1333rem;
        font-size: 0.8rem;
        color: #333333;
      }
      .span2 {
        font-size: 0.64rem;
        color: #999999;
      }
    }
    .p1 {
      width: 100%;
      height: 2.6667rem;
      color: #666666;
      border-top: 9px solid #f3f1f1;
      text-align: center;
    }
    .zsbtn {
      margin-top:1rem ;
      width: 14rem;
      height: 2rem;
      background: #f23d3d;
      color: #fff;
      opacity: 1;
      border-radius: 1.1733rem;
    }
    .p2 {
      font-size: 0.9067rem;
      color: #323233;
    }
    .pb {
      width: 13.8667rem;
      text-align: left;
      font-size: 0.8rem;
      font-family: PingFang SC;
      font-weight: 400;
      color: #9e9c9c;
      opacity: 1;
    }
    .spanp {
      font-size: 0.9067rem;
      color: #333;
    }
    .pa {
      margin-left: 0.8rem;
      color: #008be6;
    }
  }
}
</style>
